package org.softee.extractor.sax;

import static org.junit.Assert.*;

import java.io.StringReader;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;

import org.junit.Test;
import org.softee.extractor.QNameMatcher;
import org.softee.extractor.QNameMatcherFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 * Unit tests to reproduce bugs that have been found
 * 
 * @author extdivmoha
 *
 */
public class XmlExtractorTDD {
    private static final String XML_PRECEDING_COMMENT = "<root xmlns='urn:lorem:ipsum'><ignore/><!-- c2 --><child/></root>";
    private static final QNameMatcher CHILD_MATCHER = QNameMatcherFactory.combinedNameMatcher("child");
    
    @Test
    public void testIssue5DomBuilder() throws Exception {
        XmlSplitter splitter = new XmlSplitter(CHILD_MATCHER);
        List<Document> list = splitter.splitDom(createSource(XML_PRECEDING_COMMENT));
        assertEquals(1, list.size());
    }

    @Test
    public void testIssue5DomStringBuilder() throws Exception {
        XmlSplitter splitter = new XmlSplitter(CHILD_MATCHER);
        List<String> list = splitter.splitDomString(createSource(XML_PRECEDING_COMMENT));
        assertEquals(1, list.size());
    }
    
    @Test
    public void testIssue5StringBuilder() throws Exception {
        XmlSplitter splitter = new XmlSplitter(CHILD_MATCHER);
        List<String> list = splitter.splitString(createSource(XML_PRECEDING_COMMENT));
        assertEquals(1, list.size());
    }
    
    private InputSource createSource(String xml) {
        return new InputSource(new StringReader(xml));
    }

}
